<template>
    <div class="user">
        <basic-container>
            <avue-crud
                    v-model="form"
                    v-model:page="page"
                    v-model:search="searchForm"
                    :permission="getPermission"
                    v-bind="bindVal"
                    v-on="onEvent"
                    :option="option"
                    :data="tableData"
                    :before-open="beforeOpen"
            >
                <template #menu-left="{size}">
                    <el-button type="primary" icon="el-icon-plus" @click="handleInsert">新增</el-button>
                    <el-button type="primary" @click="importShowHandle()">导入</el-button>
                    <el-button type="primary" @click="exportHandle()">导出</el-button>
                </template>

                <template #menu="{ row, index, size }">
                    <el-button :size="size" icon="el-icon-edit" @click="handleUpdate(row, index)">编辑</el-button>
                </template>

            </avue-crud>

        </basic-container>

        <import-upload :base-url="pageConfig.url" :model-name="pageConfig.name" v-model="importDialogVisible"  ></import-upload>

        <el-dialog :title="红头文件" v-if="addOrUpdateVisible"   v-model="addOrUpdateVisible"  width="80%" >
            <table-form  ref="addOrUpdate"  ></table-form>
        </el-dialog>


    </div>
</template>

<script>
    import curdMixin from '@/framework-core/mixins/crud';
    import {tableOption} from "./index";
    import ImportUpload from "@/framework-core/components/upload/index.vue";
    import TableForm from "./form.vue";
    import {getCore} from "@/framework-core/api/core/api";

    export default {
        name: "oa_doc",
        mixins: [curdMixin],
        components: {ImportUpload,TableForm},
        data() {
            return {
                addOrUpdateVisible: false,
                pageConfig:{name:"","url":"/oa/oaDoc"},
                searchForm: {},
                loading: false,
                form:{},
                option: tableOption
            };
        },
        computed: {
            ...mapState({
                permissions: (state) =>state.user.permission,
            })

        },
        created() {
            this.myinitOptionDict();
            this.init();
        },
        methods: {
            init() {
            },
            addOrUpdateHandle(isEdit, id) {
                this.addOrUpdateVisible = true;
                if(id){
                    getCore(this.pageConfig.url,id).then(response => {
                        this.$nextTick(() => {
                            this.$refs.addOrUpdate.init(isEdit, response.data.data.data);
                        });

                    });
                }else{
                    this.$nextTick(() => {
                        this.$refs.addOrUpdate.init(isEdit,{});
                    });
                }

            },

            handleInsert: function(row, done, loading) {
              this.addOrUpdateHandle(false,null);
            },
            handleUpdate: function(row, index, done, loading) {
                this.addOrUpdateHandle(true,row.id);
            },

            getPermission: function (key, row, index) {
                return this.getCommPermission(key, row, index);
            },

        }
    };
</script>
<style lang="scss">

</style>
